package lee.study.Data_Struct.ClassCompare;

class Card {
    public int rank;
    public String suit;

    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (obj == null || !(obj instanceof Card)) {
            //如果obj为空或者obj不是Card的子类或者实例
            return false;
        }
        Card tmp = (Card) obj;
        if (this.rank == tmp.rank && this.suit.equals(tmp.suit)) {
            return true;
        }
        return false;
    }
}

public class cardCompare {
    public static void main(String[] args) {
        Card card = new Card(5, "♥");
        Card card1 = new Card(5, "♥");
        System.out.println(card == card1);//两个对象的引用进行比较  打印出来的是false
        System.out.println(card.equals(card1));//
    }
}
